﻿
using Mono.Cecil;
public class NewArrTree: LuaAstTree
{
    public LuaTypeReference Type { get; }
    
    public NewArrTree(LuaTypeReference type)
    {
        Type = type;
    }
    public override void WriteTo(ICodeWriter writer)
    {
        base.WriteTo(writer);
        writer.Code("{}");
    }
}

public class NewObjAstTree : LuaAstTree
{
    public LuaAstTree[] Args { get; }
    public LuaMethodReference Ctor { get; }
    public LuaTypeReference Type { get; }
    public NewObjAstTree(LuaTypeReference type, LuaMethodReference ctor, LuaAstTree[] parameters)
    {
        Type = type;
        Ctor = ctor;
        Args = parameters;
    }
    public override void WriteTo(ICodeWriter writer)
    {
        writer.Code($"new('{Type.FullName}'");
        if (Args.Any())
        {
            for (var i = 0; i < Args.Length; i++)
            {
                writer.Code(", ");
                Args[i].WriteTo(writer);
            }
        }
        writer.Code(")");
    }
}